{% set pypi_name = 'validations-libs' %}
{% set upstream_version = upstream_version('1.0.4') %}
{% set rpm_release = '1' %}
{% set source = url_pypi() %}

Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Epoch:          {{ epoch('validations-libs') }}
Summary:        A collection of python libraries for the Validation Framework
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/{{ pypi_name }}
Source0:        {{ source }}
BuildRequires:  ansible
BuildRequires:  {{ py3('ansible-runner') }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('PrettyTable') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('python-keystoneclient') }}
BuildRequires:  {{ py3('os-client-config') }}
BuildRequires:  {{ py3('oslo.utils') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('pyOpenSSL') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('testscenarios') }}
BuildRequires:  {{ py3('testtools') }}
BuildRequires:  {{ py3('warlock') }}
BuildArch:      noarch

%description
This is a collection of python libraries for the Validation Framework

#%package -n {{ py2name() }}
%package -n {{ py2name(py_versions='py3') }}
Summary:        A collection of python libraries for the Validation Framework
Requires:       ansible
Requires:       ansible-role-validations-libs
Requires:       {{ py3('ansible-runner') }}
Requires:       {{ py3('PrettyTable') }}
Requires:       {{ py3('keystoneauth1') }}
Requires:       {{ py3('oslo.i18n') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('pyOpenSSL') }}
Requires:       {{ py3('requests') }}
Requires:       {{ py3('six') }}
Requires:       {{ py3('warlock') }}
Requires:       {{ py3('wrapt') }}

%description -n {{ py2name(py_versions='py3') }}
This is a collection of python libraries for the Validation Framework.

%package -n {{ py2name() }}-doc
Summary:        Documentation for Openstack python libraries for the Validation Framework
Group:          Documentation/HTML
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('reno') }}
BuildRequires:  {{ py3('sphinxcontrib-apidoc') }}

%description -n {{ py2name() }}-doc
This is a collection of python libraries for the Validation Framework.
This package contains auto-generated documentation.

%package -n ansible-role-validations-libs
Summary:        Ansible role for the Validation Framework.

%description -n ansible-role-validations-libs
Ansible role for the Validation Framework.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

%build
%py3_build

# generate html docs
PBR_VERSION={{ upstream_version }} %sphinx_build -b html doc/source doc/build/html
PBR_VERSION={{ upstream_version }} %sphinx_build -b man doc/source doc/build/man
# remove the sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}
rm -rf doc/build/man/.{doctrees,buildinfo}

%install
%py3_install

#man pages
install -p -D -m 644 doc/build/man/validations-libs.1 \
                     %{buildroot}%{_mandir}/man1/validations-libs.1
# Temporary install of ansible roles
# will be performed on the next release directly through setup.py
# To be removed
install -p -D -m 755 -d %{buildroot}%{_datadir}/ansible/roles/validations/defaults

install -p -D -m 644 roles/validations/defaults/main.yaml \
                     %{buildroot}%{_datadir}/ansible/roles/validations/defaults/

install -p -D -m 755 -d %{buildroot}%{_datadir}/ansible/roles/validations/tasks
install -p -D -m 644 roles/validations/tasks/main.yaml  \
                     roles/validations/tasks/validations.yaml \
                     %{buildroot}%{_datadir}/ansible/roles/validations/tasks/

install -p -D -m 755 -d %{buildroot}%{_datadir}/ansible/roles/fetch-validations/defaults
install -p -D -m 644 roles/fetch-validations/defaults/main.yaml \
                     %{buildroot}%{_datadir}/ansible/roles/fetch-validations/defaults/

%check
python3 -m stestr.cli run

%files -n {{ py2name(py_versions='py3') }}
%license LICENSE
%doc README.rst ChangeLog
%{_mandir}/man1/validations-libs.1*
%{python3_sitelib}/validations_libs
%{python3_sitelib}/*.egg-info

%files -n {{ py2name() }}-doc
%license LICENSE
%doc doc/build/html

%files -n ansible-role-validations-libs
%license LICENSE
%{_datadir}/ansible/roles/fetch-validations
%{_datadir}/ansible/roles/validations

%changelog
